package cj.web.marriage.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriage.domain.UserApplication;

/**
 * 
 * @author 
 *
 */
@DAO
public interface UserApplicationDAO{
	
	@SQL("SELECT * FROM UserApplication WHERE 1=1 #if(:t.id!=null){ AND id LIKE '%##(:t.id)%' } ORDER BY createDate DESC LIMIT :t.start,:t.length ")
    List<UserApplication> query(@SQLParam("t") UserApplication userApplication);
	
	@SQL("SELECT count(1) FROM UserApplication WHERE 1=1 #if(:t.id!=null){ AND id LIKE '%##(:t.id)%' } ")
    int querysize(@SQLParam("t") UserApplication userApplication);
	
	@SQL("select * from UserApplication where openid=:1")
    UserApplication queryByOpenId(String openid);
    
    @SQL("select * from UserApplication where id=:1")
    UserApplication queryById(String id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO UserApplication (id,openid,nickname,sex,city,province,country,headimgurl,createDate) VALUES (:t.id,:t.openid,:t.nickname,:t.sex,:t.city,:t.province,:t.country,:t.headimgurl,now())")
    public int create(@SQLParam("t") UserApplication userApplication);
	
	@SQL("UPDATE UserApplication SET openid=:t.openid,nickname=:t.nickname,sex=:t.sex,city=:t.city,province=:t.province,country=:t.country,headimgurl=:t.headimgurl,unionid=:t.unionid,code=:t.code WHERE id=:t.id")
    void update(@SQLParam("t") UserApplication userApplication);
	
	@SQL("UPDATE UserApplication SET code=:1 WHERE openid=:2")
	void updateCode(String code,String openid);
}